package com.lsa.shenn.common;

import java.util.Arrays;

import com.lsa.helpers.Utils;

import junit.framework.TestCase;

public abstract class SorterTestCaseBase extends TestCase
{
	protected void testSorter(Sorter sorter)
	{
		testWithArray(sorter, new int[]{8, 9, 1, 7, 1, 2, 5, 8, 9, 4}, 
				"1 1 2 4 5 7 8 8 9 9");
		
		testWithArray(sorter, new int[]{-5,-1,-3,-17}, 
				"-17 -5 -3 -1");
		
		testWithArray(sorter, new int[]{-7, 8, 9, 1, 7, -1, 2, -5, 8, 9, 4}, 
			"-7 -5 -1 1 2 4 7 8 8 9 9");
		
		testWithArray(sorter, new int[]{8, 9, 1, 12, 1, 2, 5, 8, 9, 4, 15 , 13, 121, 0, 1}, 
				"0 1 1 1 2 4 5 8 8 9 9 12 13 15 121");
		
		testWithArray(sorter, new int[]{3,33,333,3,33333,123,3000,30000,300}, 
				"3 3 33 123 300 333 3000 30000 33333");
		
		testWithArray(sorter, new int[]{8, 9, 1, 12, 1, 2, 5, 8, 9, 4, 13, 0, 1}, 
		"0 1 1 1 2 4 5 8 8 9 9 12 13");
		
		testWithArray(sorter, new int[]{8, 9, 1, 12, 1, 2, 5, 8, 9, 4, 13, 0, 1}, 
		"0 1 1 1 2 4 5 8 8 9 9 12 13");
		
		testWithArray(sorter, new int[]{8, 9, 1, 7, 1, 2, 5, 8, 9, 4}, 
		"1 1 2 4 5 7 8 8 9 9");
		
		testWithArray(sorter, new int[]{-5,-3,-2,-10}, 
		"-10 -5 -3 -2");
		
		testWithArray(sorter, new int[]{9, 4}, 
		"4 9");
		
		testWithArray(sorter, new int[]{9, 4, 1}, 
		"1 4 9");
		
		testWithArray(sorter, new int[]{9}, 
		"9");
		
		testWithArray(sorter, new int[]{3,3,3,3,3,3,3,3,3}, 
				"3 3 3 3 3 3 3 3 3");
		
		testWithArray(sorter, new int[]{}, 
		" ");
	}
	
	protected void testWithArray(Sorter sorter, int[] array, String strTestArray)
	{
		array = sorter.sort(array);
		int[] testArray = Utils.createIntArray1D(strTestArray);
		assertEquals(Arrays.toString(array)+" " + Arrays.toString(testArray), true, Utils.compareArrays(array, testArray));
	}
	
	//8, 9, 1, 7, 1, 2, 5, 8, 9, 4
}
